/**
 * @(#)EToolActivity.java, 2016年2月29日. Copyright 2016 Yodao, Inc. All rights
 * reserved. YODAO PROPRIETARY/CONFIDENTIAL. Use is
 * subject to license terms.
 */
package com.scitc.pleasurevideo.base;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.TypedArray;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.githang.statusbar.StatusBarCompat;
import com.scitc.pleasurevideo.R;
import com.umeng.analytics.MobclickAgent;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

/**
 * @author lukun
 */
public class ETActivity extends SwipeBackActivity {

    protected AppCompatActivity mInstance;
    protected static MyHashMap<String, String> valueMap;


    public String getStatType() {
        return "";
    }

    public String getStatValue() {
        return "";
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mInstance = this;
        valueMap = new MyHashMap<String, String>();
        //StatGraph.doPageStart(this);
        StatusBarCompat.setStatusBarColor(this, getResources().getColor(R.color.white), true);
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
            boolean result = fixOrientation();
        }
    }


    private boolean isTranslucentOrFloating() {
        boolean isTranslucentOrFloating = false;
        try {
            int[] styleableRes = (int[]) Class.forName("com.android.internal.R$styleable").getField("Window").get(null);
            final TypedArray ta = obtainStyledAttributes(styleableRes);
            Method m = ActivityInfo.class.getMethod("isTranslucentOrFloating", TypedArray.class);
            m.setAccessible(true);
            isTranslucentOrFloating = (boolean) m.invoke(null, ta);
            m.setAccessible(false);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isTranslucentOrFloating;
    }


    @Override
    public void setRequestedOrientation(int requestedOrientation) {
        if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O && isTranslucentOrFloating()) {
            return;
        }
        super.setRequestedOrientation(requestedOrientation);
    }

    private boolean fixOrientation() {
        try {
            Field field = Activity.class.getDeclaredField("mActivityInfo");
            field.setAccessible(true);
            ActivityInfo o = (ActivityInfo) field.get(this);
            o.screenOrientation = -1;
            field.setAccessible(false);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }

    @Override
    public void finish() {
        super.finish();
        //overridePendingTransition(0, R.anim.listen_activity_close_out_anim);
    }

    @Override
    protected void onResume() {
        super.onResume();
        //StatGraph.doPageResume(this.getClass().getSimpleName(), this);
        try {
            // MobclickAgent.onPageStart(getIdentity());
            MobclickAgent.onResume(this);
        } catch (Exception e) {
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        //StatGraph.doPageRestart(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //StatGraph.doPagePause(this);
        try {
            // MobclickAgent.onPageEnd(getIdentity());
            MobclickAgent.onPause(this);
        } catch (Exception e) {
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        //StatGraph.doPageStop(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mInstance = null;
        //StatGraph.doPageEnd(this, getStatType(), getStatValue(), getStatMap());
    }

    public void loginBack(View view) {
        finish();
    }
}
